package com.example.leetcode;

import java.util.Stack;

/**
 * Created by Quincy on 2018/9/14.
 */
public class IsSymmetric {
    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    public static boolean isSymmetric(ListNode node){
        Stack<ListNode> st = new Stack<ListNode>();
        boolean flag = true;
        ListNode p = node;
        ListNode q = null;
        while (p != null){
            st.push(p);
            p = p.next;
        }
        p = node;
        while (p != null){
            q = st.pop();
            if (p.val != q.val){
                flag = false;
                break;
            }
            p = p.next;
        }
        return flag;
    }
}
